var express = require("express");
var router = express.Router();
var multer = require('multer');
var fs = require('fs');
var upload = multer({
  "dest": "uploads"
});

const arr = [];
router.get("/img/:filename", function(req,res){
  fs.createReadStream("uploads/"+req.params.filename).pipe(res);
});

router.post("/up", upload.single("imgfile"), function(req,res){
  arr.push(req.file);
  // res.render("back");
  // console.log(req.file);
  res.send(req.file);
  console.log(arr);
});


router.get("/", function(req,res){
  res.locals.list = arr;
  res.render("ajaxdemo");
});

module.exports = router;
